package com.wanxi.util;

import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author 杨金乾
 */
public class Tool {

    /**
     * USER_LOGIN_INFO 用户登录成功后的标记
     */
    public static final String USER_LOGIN_INFO = "userinfo";
    private Tool() {

    }

    public static int strToInt(String value) {
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            return -1;
        }
    }

    public static Integer strToPage(String value) {
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            return 1;
        }
    }

    public static Integer strToLimit(String value) {
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            return 10;
        }
    }
    public static String nullToStr(String value) {

        return value == null ? "" : value.trim();

    }

    public static String nullToDate(String value) {

        return value == null ? "" : value.trim();

    }
    public static BigDecimal nullToDecimal(String value) {
        try {
            return new BigDecimal(value);
        } catch (Exception e) {
            return new BigDecimal("0");
        }
    }
    public  static  String time(){
        Date date=new Date();
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format(date);
    }

}
